#ifndef _WRAPPER_H__
#define _WRAPPER_H__
#include <stdio.h>
#include <unistd.h>
#include <signal.h>
#include <errno.h>

#include <proc/connection.h>
#include <proc/command.h>
#include <proc/exception.h>

#include <map>
using namespace std;

#include "tableschema.h"
#include "str.h"
#include "load.h"

class Wrapper
{
protected:
	Wrapper();
	~Wrapper();
	
public:
	static Wrapper *instance()
	{
		if (wapper == 0){
			wapper = new Wrapper();
		}
		return wapper;
	}
	
	int open(int argc, char **argv);
	int loadData();
	
	static void cleanup()
	{
		if (wapper != 0){
			delete wapper;
			wapper = 0;
		}		
	}

	
private:	
	static void signalAbort(int n)
	{
		printf("DB Merge abort. signal=%d\n", n);
		exit(-1);
	}
	
private:
	int getopt(int argc, char **argv);
	void usage(char *name);
	int open();
	void clear();
	int sigaction(int signum);
	int sigaction();
	
private:
	Connection *connection;
	TableMapping *tableMapping;
	Load *load;
	
	string sid, user, password;
	string configFile;
	
	map<string, string> parameters;
		
	static Wrapper *wapper;
};

#endif
